package com.zpark.servlet_response;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @PackageName: com.zpark.servlet_response
 * @ClassName: ServletResponseDemo02
 * @Description:
 * @author: RZS
 * @date: 2023/3/9  17:05
 */
@WebServlet("/sp02.do")
public class ServletResponseDemo02 extends HttpServlet {
    @Override
    protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        // 设置响应头
        response.addHeader("zs", "zhangsan");
        response.setHeader("zs", "你已经被我修改，hahahahah");

        // 设置 Servlet 输出内容的 MIME 类型以及编码格式。
        response.setContentType("text/html;charset=UTF-8");
        response.setCharacterEncoding("utf-8");
        response.getWriter().println("<h1>设置 Servlet 输出内容的 MIME 类型以及编码格式</h1>");
    }
}
